package kcms.ppt.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import kcms.course.dao.CourseDao;
import kcms.db.CourseJiaoke;
import kcms.db.Ppt;
import kcms.db.PptAndContent;
import kcms.db.PptTeaContent;
import kcms.db.Pptcontent;
import kcms.db.Shangke;
import kcms.db.User;
import kcms.ppt.dao.PptDao;
import kcms.ppt.service.PptService;

@Service
public class PptServiceImpl implements PptService{
	
	@Resource
	private PptDao pptdao;
	public PptDao getPptdao() {
		return pptdao;
	}
	public void setPptdao(PptDao pptdao) {
		this.pptdao = pptdao;
	}
	@Resource
	private List<CourseJiaoke> coursejiaoke;
	public List<CourseJiaoke> getCoursejiaoke() {
		return coursejiaoke;
	}
	public void setCoursejiaoke(List<CourseJiaoke> coursejiaoke) {
		this.coursejiaoke = coursejiaoke;
	}
	@Resource
	private CourseDao coursedao;
	public CourseDao getCoursedao() {
		return coursedao;
	}
	public void setCoursedao(CourseDao coursedao) {
		this.coursedao = coursedao;
	}
	@Resource
	private List<Pptcontent> pptcontent;
	public List<Pptcontent> getPptcontent() {
		return pptcontent;
	}
	public void setPptcontent(List<Pptcontent> pptcontent) {
		this.pptcontent = pptcontent;
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public int queryPptId(String cid,String csn,String chapter){
		return pptdao.queryPptId(cid,csn,chapter);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public Pptcontent deletePptResourceByPptid(Integer pptid){
		return pptdao.deletePptResourceByPptid(pptid.intValue());
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public Ppt createNewPptid(String cid,String csn,String chapter){
		return pptdao.createNewPptid(cid, csn, chapter);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean saveContentRecord(Integer pptid, String generatedname,
			String originalname, String description){
		return pptdao.saveContentRecord(pptid,generatedname,originalname,description);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public List<CourseJiaoke> getAllCourseAttendedBy(User u){
		coursejiaoke.clear();
		CourseJiaoke cj;
		List<Shangke> sk=coursedao.getAllCoursesCidCsn(u);
		for(Shangke shangke:sk){
			System.out.println(shangke.getId().getCid()+shangke.getId().getCsn());
			cj=coursedao.getByCidCsn(shangke.getId().getCid(),shangke.getId().getCsn());
			System.out.println(cj.getSn());
			coursejiaoke.add(cj);
		}
		return coursejiaoke;
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public List<PptAndContent> listPpt(String[] checkbox, String search, String startdate, String enddate, int currentpage, int pagesize){
		StringBuffer sb1=new StringBuffer();
		StringBuffer sb2=new StringBuffer();
		if(checkbox!=null&&checkbox.length!=0){
			for(String c:checkbox){
				String temp[]=c.split("@");
				sb1.append(temp[0]+",");
				sb2.append(temp[1]+",");
			}
			return pptdao.listPpt(sb1.substring(0,sb1.length()-1),sb2.substring(0,sb2.length()-1),search,startdate,enddate,currentpage,pagesize);
			
		}else{
			return pptdao.listPpt("-","-",search,startdate,enddate,currentpage,pagesize);
			//查全部的记录
		}
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public Pptcontent getRealFileNameByPptid(String pptid){
		return pptdao.getRealFileNameByPptid(pptid);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public List<PptTeaContent> listPptByTid(String id){
		return pptdao.listPptByTid(id);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean deletePptByPptid(String pptid){
		return pptdao.deletePptByPptid(pptid);
	}
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean deleteAllPptStatusByPptid(String pptid){
		return pptdao.deleteAllPptStatusByPptid(pptid);
	}
}
